package wxb.avalon.core.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private boolean success = Boolean.TRUE;

    private int code = 200;

    private String msg;

    private T data;

    public Result<T> ok(){
        this.success = Boolean.TRUE;
        this.setCode(200);
        this.setMsg("操作成功");
        return this;
    }

    public Result<T> ok(T data){
        this.success = Boolean.TRUE;
        this.setCode(200);
        this.setMsg("操作成功");
        this.setData(data);
        return this;
    }

    public Result<T> ok(String msg, T data){
        this.success = Boolean.TRUE;
        this.setCode(200);
        this.setMsg(msg);
        this.setData(data);
        return this;
    }

    public Result<T> fail(int code, String msg){
        this.success = Boolean.FALSE;
        this.setCode(code);
        this.setMsg(msg);
        return this;
    }

    public Result<T> fail(String msg){
        this.success = Boolean.FALSE;
        this.setCode(500);
        this.setMsg(msg);
        return this;
    }

    public Result<T> fail(String msg, T data){
        this.success = Boolean.FALSE;
        this.setCode(500);
        this.setMsg(msg);
        this.setData(data);
        return this;
    }

    public Result<T> fail(){
        this.success = Boolean.FALSE;
        this.setCode(500);
        this.setMsg("操作失败");
        return this;
    }
}
